package com.liming.business.controller.admin;

import com.liming.server.dto.ResponseDto;
import com.liming.server.dto.SectionDto;
import com.liming.server.dto.SectionPageDto;
import com.liming.server.service.SectionService;
import com.liming.server.util.ValidatorUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/section")
public class SectionController {
    public static final String BUSINESS_NAME="小节";

    @Resource
    private SectionService sectionService;

    @PostMapping("/list")
    public ResponseDto list(@RequestBody SectionPageDto sectionPageDto){
        ResponseDto responseDto = new ResponseDto();
        ValidatorUtil.require(sectionPageDto.getCourseId(),"课程Id");
        ValidatorUtil.require(sectionPageDto.getChapterId(),"大章Id");
        sectionService.list(sectionPageDto);
        responseDto.setContent(sectionPageDto);
        return responseDto;
    }
    @PostMapping("/save")
    public ResponseDto save(@RequestBody SectionDto sectionDto){

        //保存校验
        ValidatorUtil.require(sectionDto.getTitle(),"标题");
        ValidatorUtil.length(sectionDto.getTitle(),"标题",1,50);
        ValidatorUtil.length(sectionDto.getVideo(),"视频",1,200);

        ResponseDto responseDto = new ResponseDto();
        sectionService.save(sectionDto);
        responseDto.setContent(sectionDto);
        return responseDto;
    }

    @DeleteMapping("/delete/{id}")
    public ResponseDto delete(@PathVariable String id){
        ResponseDto responseDto = new ResponseDto();
        sectionService.delete(id);
        return responseDto;
    }
}
